package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Delete implements Ioperation{
    @Override
    public void work(BookList booklist) {
        int currentSize = booklist.getCurrentSize();
        if(currentSize == 0){
            System.out.println("书架为空，无法进行删除操作！！！");
            return;
        }

        Scanner scan = new Scanner(System.in);
        System.out.println("请输入你要删除的图书书名：");
        String bookName = scan.nextLine();

        for (int i = 0; i < currentSize; i++) {
            Book book = booklist.getBooks(i);
            if(book.getName().equals(bookName)){
                for (int j = i; j < currentSize - 1; j++) {
                    booklist.setBooks(j, booklist.getBooks(j+1));
                }
                booklist.setCurrentSize(currentSize - 1);
                System.out.println("删除成功......");
                return;
            }
        }
        System.out.println("没有你要删除的书");
    }
}
